{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to atomman: DFT reference crystal loading\n",
    "\n",
    "__Lucas M. Hale__, [lucas.hale@nist.gov](mailto:lucas.hale@nist.gov?Subject=ipr-demo), _Materials Science and Engineering Division, NIST_.\n",
    "    \n",
    "[Disclaimers](http://www.nist.gov/public_affairs/disclaimer.cfm) \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Introduction<a id='section1'></a>\n",
    "\n",
    "In addition to the crystal structures in the NIST Repository, crystal structures can also be obtained directly from the [Materials Project](https://materialsproject.org/) and [OQMD](http://oqmd.org/) DFT databases.  This provides a means of performing direct comparisons of crystal structure predictions between DFT and classical potentials and offers the opportunity to explore more proposed crystal structures.\n",
    "\n",
    "*Added version 1.4.0*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Library Imports**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atomman version = 1.4.0\n",
      "Notebook executed on 2021-08-04\n"
     ]
    }
   ],
   "source": [
    "# Standard Python libraries\n",
    "import datetime\n",
    "\n",
    "# http://www.numpy.org/\n",
    "import numpy as np\n",
    "\n",
    "import atomman as am\n",
    "import atomman.unitconvert as uc\n",
    "\n",
    "# Show atomman version\n",
    "print('atomman version =', am.__version__)\n",
    "\n",
    "# Show date of Notebook execution\n",
    "print('Notebook executed on', datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. atomman.load('prototype')<a id='section2'></a>\n",
    "\n",
    "Accesses the potentials database to retrieve a crystal_prototype record and generate a unit cell System based on it.\n",
    "\n",
    "Query parameters\n",
    "\n",
    "- __id__ (*str*) The reference crystal's unique id.  Combines a database tag \"mp-\" or \"oqmd-\" and the DFT database's entry id.\n",
    "- __api_key__ (*str, optional*) The user's Materials Project API key or path to a file containing the key. Only needed for fetching structures from Materials Project and if the key is not set to the \"MAPI_KEY\" environment variable.\n",
    "\n",
    "Database option parameters\n",
    "\n",
    "- __database__ (*atomman.library.Database, optional*) A pre-defined Database object to use.  If not given, will initialize a new Database object.  Passing in a database can save time if multiple calls are made for the same record type.  \n",
    "- __local__ (*bool, optional*) Indicates if the Database object is to look for local records.  Default is True.  Ignored if database is given.\n",
    "- __remote__ (*bool, optional*) Indicates if the Database object is to look for remote records.  Default is True.  Ignored if database is given.\n",
    "- __refresh_cache__ (*bool, optional*) If the local database is of style \"local\", indicates if the metadata cache file is to be refreshed.  If False, metadata for new records will be added but the old record metadata fields will not be updated.  If True, then the metadata for all records will be regenerated, which is needed to update the metadata for modified records.\n",
    "- __verbose__ (*bool, optional*) If True, info messages will be printed during operations.  Default value is False.\n",
    "\n",
    "Returns\n",
    "    \n",
    "- __system__ (*atomman.System*) The system object generated from the crystal prototype."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Fetch the relaxed fcc Au structure from both databases"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crystal retrieved from Materials Project\n",
      "avect =  [ 4.171,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  4.171,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  4.171]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 4\n",
      "natypes = 1\n",
      "symbols = ('Au',)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   0.000 |   2.086 |   2.086\n",
      "      2 |       1 |   2.086 |   0.000 |   2.086\n",
      "      3 |       1 |   2.086 |   2.086 |   0.000\n"
     ]
    }
   ],
   "source": [
    "mp_api_key = 'C:/Users/lmh1/Documents/Materials Project/API key.txt'\n",
    "\n",
    "ucell = am.load('dft_reference', 'mp-81', api_key=mp_api_key, verbose=True)\n",
    "print(ucell)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Crystal retrieved from OQMD\n",
      "avect =  [ 4.125,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  4.125,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  4.125]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 4\n",
      "natypes = 1\n",
      "symbols = ('Au',)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   2.063 |   2.063 |   0.000\n",
      "      2 |       1 |   2.063 |   0.000 |   2.063\n",
      "      3 |       1 |   0.000 |   2.063 |   2.063\n"
     ]
    }
   ],
   "source": [
    "ucell = am.load('dft_reference', 'oqmd-592562', verbose=True)\n",
    "print(ucell)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
